home *** CD-ROM | disk | FTP | other *** search
/ SGI Freeware 1999 August / SGI Freeware 1999 August.iso / dist / fw_mc.idb / usr / freeware / lib / mc / extfs / lha.z / lha
Encoding:
Text File  |  1998-10-28  |  4.2 KB  |  137 lines

  1. #! /bin/sh
  2.  
  3. #
  4. # LHa Virtual filesystem executive v0.1
  5. # Copyright (C) 1996, 1997 Joseph M. Hinkle
  6. # May be distributed under the terms of the GNU Public License
  7. # <jhinkle@rockisland.com>
  8. #
  9.  
  10. # Code for mc_lha_fs_run() suggested by:
  11. # Jan 97    Zdenek Kabelac <kabi@informatics.muni.cz>
  12.  
  13. # Tested with mc 3.5.18 and gawk 3.0.0 on Linux 2.0.0
  14. # Tested with lha v1.01 and lharc v1.02
  15. # Information and sources for other forms of lha/lzh appreciated
  16.  
  17. # Nota bene:
  18. # There are several compression utilities which produce *.lha files.
  19. # LHArc and LHa in exist several versions, and their listing output varies.
  20. # Another variable is the architecture on which the compressed file was made.
  21. # This program attempts to sort out the variables known to me, but it is likely
  22. # to display an empty panel if it encounters a mystery. 
  23. # In that case it will be useful to execute this file from the command line:
  24. # ./lha list Mystery.lha
  25. # to examine the output directly on the console.  The output string must be
  26. # precisely in the format described in the README in this directory.
  27. # Another helpful thing is to temporarily remove the redirection of error
  28. # output of awk (The '2> /dev/null' instruction near the end of mcfs_list())
  29. # The screen will get ugly if there's an error, but some useful text shows
  30. # at the bottom of the screen.  
  31. # Caveat emptor.
  32. # Learn Latin.
  33.  
  34. # Define your awk
  35. AWK=nawk
  36. # Define which archiver you are using with appropriate options
  37. LHA_LIST="lha l"
  38. LHA_GET="lha pq"
  39. LHA_PUT="lha a"
  40.  
  41. # Define the temporary name of a command to be run from the archive
  42. TMPCMD=/tmp/mc-cmd.$$
  43.  
  44. # The 'list' command executive
  45.  
  46. mc_lha_fs_list()
  47. {
  48.    # Get the year of the file timestamp in case we need to replace 'hh:mm'
  49.    YEAR=$(ls -le $1 | $AWK '{ print $10 }')
  50.    # List the contents of the archive and sort it out    
  51.    $LHA_LIST $1 | $AWK -v uid=$(id -nu) -v gid=$(id -ng) -v year=$YEAR '
  52.       # Ignore the annotations, quit on the last one
  53.       /^\ PERMSSN/ { next }
  54.       /^-----/ { next }
  55.       /^\ Total/ { exit 0 }
  56.       # Strip a leading '/' if present in a filepath
  57.       $(NF) ~ /^\// { $(NF) = substr($NF,2) }
  58.       # Replace the year stamp if it is expressed as 'hh:mm'
  59.       $(NF-1) ~ /\:/ { $(NF-1) = year }
  60.       # Print the line this way if there is no permission string
  61.       $1 ~ /^\[generic\]/ {
  62.          # Invent a generic permission
  63.          $1 = ($10 ~ /\/$/) ? "drwxr-xr-x":"-rwxr-xr-x";
  64.          # Print it
  65.          printf "%s   1 %-8s %-8s %-8d %3s %2d %4d %s\n",
  66.                  $1,     uid, gid,  $2, $4, $5, $6, $7;
  67.          # Get the next line of the list
  68.          next;
  69.       }
  70.       # Do it this way for a defined permission
  71.       $1 !~ /^\[generic\]/ {
  72.          # If the permissions and UID run together
  73.          if ($1 ~ /\//) {
  74.             $8 = $7;
  75.             $7 = $6;
  76.             $6 = $5;
  77.             $5 = $4;
  78.             $3 = $2;
  79.             $2 = substr($1,10);
  80.             $1 = substr($1,1,9);
  81.          }
  82.          # If the permission string is missing a type
  83.          if (length($1) == 9) {
  84.             if ($NF ~ /\/$/)
  85.                $1 = ("d" $1);
  86.             else
  87.                $1 = ("-" $1);
  88.          }
  89.          # UID:GID might not be the same as on your system so print numbers
  90.          # Well, that is the intent.  At the moment mc is translating them.
  91.          split($2, id, "/");
  92.          printf "%s   1 %-8d %-8d %-8d %3s %2d %4d %s\n",
  93.                  $1,     id[1], id[2],  $3, $5, $6, $7, $8;
  94.          # Get the next line of the list
  95.          next;
  96.       }
  97.  
  98.    ' 2> /dev/null
  99. }
  100.  
  101. # The 'copyout' command executive to copy displayed files to a destination
  102.  
  103. mc_lha_fs_copyout()
  104. {
  105.    $LHA_GET $1 $2 > $3  2> /dev/null
  106. }
  107.  
  108. # The 'copyin' command executive to add something to the archive
  109.  
  110. mc_lha_fs_copyin ()
  111. {
  112.    # This isn't called from this version of mc
  113.    $LHA_PUT $1 $3  2> /dev/null
  114. }
  115.  
  116. # The 'run' command executive to run a command from within an archive
  117.  
  118. mc_lha_fs_run()
  119. {
  120.    trap "rm $TMPCMD; exit 0" 1 2 3 4 15
  121.    $LHA_GET $1 $2 > $TMPCMD  2> /dev/null
  122.    chmod a+x $TMPCMD  2> /dev/null
  123.    $TMPCMD 2> /dev/null
  124.    rm $TMPCMD
  125. }
  126.  
  127.  
  128. # The main routine
  129. case "$1" in
  130.    list) mc_lha_fs_list $2; exit $?;;
  131.    copyout) mc_lha_fs_copyout $2 $3 $4; exit $?;;
  132.    copyin)  mc_lha_fs_copyin  $2 $3 $4; exit $?;;
  133.    run)     mc_lha_fs_run     $2 $3 $4; exit $?;;
  134. esac
  135. exit 1
  136.  
  137.